using Dapr.Actors;
using Dapr.Actors.Client;
using Furion.DynamicApiController;
using Kevin.Dapr.Actors;
using Kevin.Dapr.IActors;
using Microsoft.AspNetCore.Mvc;

namespace Kevin.Dapr.Api.Controllers
{
    public class SeckillController : IDynamicApiController
    {
        public static readonly string actorid = Guid.NewGuid().ToString();

        [HttpPost]
        public async Task InitSku(long number)
        {
            var actor = GetSeckill_Actor(actorid);
            await actor.InitSku(actorid, number);
        }

        // Dotnet-Netty

        [HttpPost]
        public async Task AddOrder()
        {
            var actor = GetSeckill_Actor(actorid);
            await actor.AddOrder();
        }


        [HttpPost]
        public async Task<long> GetSku()
        {
            var actor = GetSeckill_Actor(actorid);
            var data = await actor.GetSku();
            return data;
        }

        public static ISeckillActor GetSeckill_Actor(string _actorid)
        {
            var actorId = new ActorId(_actorid.ToString());
            return ActorProxy.Create<ISeckillActor>(actorId, nameof(SeckillActor));
        }
    }
}
